<?php
require_once("database/db_connect.php"); 
require_once("database/get_xml.php");
require_once("database/db_mars_get_set.php");

$currentConnection = CreateNewDBConnection("mars");
//$xml = getXml("http://cab.inta-csic.es/rems/rems_weather.xml");
//insertWeatherXmlToDatabase($xml, $currentConnection);
//ReadWeatherReport($currentConnection, 350currentReport);
if (isset( $_GET["date"])) {
	$sol = calcSol($_GET["date"]);
	//print("<h1>".$sol."</h1>");
	$currentReport = ReadWeatherReport($currentConnection, $sol);
}
else {
	$currentReport = GetLastWeatherReport($currentConnection);	
}

//print("<h1>".$lastReport['sol']."</h1>");
$currentConnection->close();

function calcSol($date)
{
    define("START_DATE_STAMP", 947116800);
    define("CURIOSITY_LAND_STAMP", 1344231120);
    $inputDateStamp = strtotime($date);
    $solOfCuriosityLand = (START_DATE_STAMP - CURIOSITY_LAND_STAMP)/88775.244 + 44795.9998;
    $solOfGivenDate = (START_DATE_STAMP - $inputDateStamp)/88775.244 + 44795.9998;
    $sol = floor($solOfCuriosityLand - $solOfGivenDate + 1);
    return $sol;
}

?>